home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- * Poly_cln.c - Clean polygonal data. *
- *******************************************************************************
- * Written by Gershon Elber, June 1993. *
- ******************************************************************************/
-
- #include "irit_sm.h"
- #include "allocate.h"
- #include "iritprsr.h"
- #include "poly_cln.h"
-
- /*****************************************************************************
- * Routine to clean up polygons - delete zero length edges, and polygons *
- * with less than 3 vertices. *
- *****************************************************************************/
- void CleanUpPolygonList(IPPolygonStruct **PPolygons)
- {
- IPPolygonStruct *PPHead, *PPLast;
- IPVertexStruct *PVHead, *PVTemp, *PVNext;
-
- PPLast = PPHead = *PPolygons;
-
- while (PPHead != NULL) {
- PVHead = PVTemp = PPHead -> PVertex;
- /* Look for zero length edges (V == V -> Pnext): */
- do {
- PVNext = PVTemp -> Pnext;
- if (PT_APX_EQ(PVTemp -> Coord, PVNext -> Coord)) { /* Del PVNext.*/
- PVTemp -> Pnext = PVTemp -> Pnext -> Pnext;
- PVNext -> Pnext = NULL; /* Free only PVNext. */
- if (PVHead == PVNext) { /* If we actually kill header. */
- PPHead -> PVertex = PVHead = PVTemp;
- break;
- }
- IPFreeVertexList(PVNext);
- }
- else
- PVTemp = PVTemp -> Pnext;
- }
- while (PVTemp != NULL && PVTemp != PVHead);
-
- /* Now test if at list 3 vertices in polygon, otherwise delete it: */
- if (PVHead == PVHead -> Pnext || /* One vertex only. */
- PVHead == PVHead -> Pnext -> Pnext) { /* Two vertices only. */
- if (PPHead == *PPolygons) {
- *PPolygons = (*PPolygons) -> Pnext;
- IPFreePolygon(PPHead);
- PPHead = (*PPolygons);
- }
- else {
- PPLast -> Pnext = PPHead -> Pnext;
- IPFreePolygon(PPHead);
- PPHead = PPLast -> Pnext;
- }
- }
- else {
- PPLast = PPHead;
- PPHead = PPHead -> Pnext;
- }
- }
- }
-
- /*****************************************************************************
- * Routine to clean up polylines of zero length. *
- *****************************************************************************/
- void CleanUpPolylineList(IPPolygonStruct **PPolylines)
- {
- IPPolygonStruct
- *Poly = *PPolylines;
-
- /* Remove empty sized polylines. */
- while (Poly != NULL &&
- (Poly -> PVertex == NULL ||
- Poly -> PVertex -> Pnext == NULL)) {
- *PPolylines = (*PPolylines) -> Pnext;
- IPFreePolygon(Poly);
- Poly = *PPolylines;
- }
-
- if (Poly && Poly -> Pnext) {
- while (Poly -> Pnext != NULL) {
- if (Poly -> Pnext -> PVertex == NULL ||
- Poly -> Pnext -> PVertex -> Pnext == NULL) {
- IPPolygonStruct
- *TmpPoly = Poly -> Pnext;
-
- Poly -> Pnext = TmpPoly -> Pnext;
- IPFreePolygon(TmpPoly);
- }
- else
- Poly = Poly ->Pnext;
- }
- }
- }
-